package myEddy.operator;

import java.util.ArrayList;
import java.util.Queue;

import myEddy.core.Eddy;
import myEddy.tuple.Tuple;

/**
 * 
 * Abstract class defining the operators.
 * It contains the needed method and some attributes.
 * For the time being, it shall work as a thread.
 * 
 * @author Nathan Ramoly
 *
 */
public abstract class Operator implements Runnable
{
	
	/** Attributes **/
	
	/**
	 * Input queue. IOW, FIFO of tuples to deal with
	 */
	protected Queue<Tuple> input;
	
	/**
	 * Performance indicator
	 */
	protected int perf_ind;
	
	/**
	 * Tables the operator deal with.
	 */
	protected ArrayList<String> tables;
	
	/**
	 * Id of this operator
	 * It shall be its position in the array in Eddy
	 */
	protected int id;
	
	/**
	 * Parent Eddy containing the operator
	 */
	protected Eddy parent;
	
	/**
	 * Tell if the thread loop is activated or not
	 */
	protected boolean running;
	
	
	/** Methods **/
	
	/**
	 * Set the id
	 */
	public void setId( int new_id )
	{
		id = new_id;		
	}
	
	/**
	 * Add a new tuple to deal with
	 * @param new_tuple new_tuple to add
	 */
	public void addTuple( Tuple new_tuple )
	{
		input.add(new_tuple);
	}

	/**
	 * Get the tables of the tuples the operator work on.
	 * @return Table
	 */
	public ArrayList<String> getTables()
	{
		return tables;
	}
	
	/**
	 * Set the parent
	 */
	public void setParent( Eddy ed )
	{ 
		parent = ed; 
	}
	
	
	/** Abstract methods **/
	
	/**
	 * The operator do its job
	 * @param T Tuple do deal with
	 * @return All tuples generated by the operation, null if no result
	 */
	abstract ArrayList<Tuple> Operate(Tuple T);
	
	/**
	 * Return the performance of the operator.
	 * @see perf_ind
	 * @return perf_ind
	 */
	public abstract int getPerfInd();
	
	/**
	 * Send the computed tuples to eddy
	 * @param Results Computed tuple to send
	 */
	abstract void sendResultTuple( ArrayList<Tuple> results );
	


}
